package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.exception.MallException;
import com.ymk.bo.user.MchDeskBO;
import com.ymk.core.code.cmd.UserCmdCode;
import com.ymk.core.enums.mch.MchDeskStatusEnum;
import com.ymk.service.IMchDeskService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class MchDeskPostCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        MchDeskBO mchDeskBO = super.getData(sign, MchDeskBO.class);
        mchDeskBO.setMchId(sign.getMchId());
        mchDeskBO.setStatus(MchDeskStatusEnum.NORMAL.getStatus());

        String unlimitedQRCode = this.mchDeskService.getUnlimitedQRCode(mchDeskBO);
        if (StringUtils.isBlank(unlimitedQRCode)){
            throw new MallException("服务异常");
        }
        mchDeskBO.setQrCode(unlimitedQRCode);

        super.setCreatedData(sign,mchDeskBO);
        this.mchDeskService.post(mchDeskBO);
        respSign.setSource(super.getSource(mchDeskBO));
        return respSign;
    }

    @Override
    public String getCmdCode() {
        return UserCmdCode.MCH_DESK_POST;
    }

    @Autowired
    private IMchDeskService mchDeskService;
}